package com.kitwee.serialport.data.model;

public enum Parity {

    /**
     * 不校验
     */
    None('n'),

    /**
     * 奇校验
     */
    Odd('o'),

    /**
     * 偶校验
     */
    Even('e');

    private final char value;

    Parity(char value) {
        this.value = value;
    }

    public static Parity fromValue(String value) {
        return fromValue(value.charAt(0));
    }

    public static Parity fromValue(char value) {
        switch (value) {
            case 'n':
            case 'N':
                return None;
            case 'o':
            case 'O':
                return Odd;
            case 'e':
            case 'E':
                return Even;
            default:
                throw new IllegalArgumentException("Invalid value!");
        }
    }

    public char value() {
        return value;
    }

}
